package com.dy.security.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @ClassName:
 * @Author: dingyu
 * @Desctiption: (描述)
 * @Date: 2022/3/30 17:18
 * @Version 1.0 (版本)
 */
@Data
@Accessors(chain = true)
@TableName("users")
public class UsersEntity implements Serializable, UserDetails {
    /**
     * id
     */
    @TableId(type = IdType.AUTO)
    private Long id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 账号是否生效
     */
    private Boolean enable;
    /**
     * 角色集合逗号隔开
     */
    private String roles;

    private List<GrantedAuthority> authorities;

    /**
     * 对应角色集合
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 对应用户是否可用
     * @return
     */
    @Override
    public boolean isEnabled() {
        return this.enable;
    }
}
